home *** CD-ROM | disk | FTP | other *** search
/ Nebula 2 / Nebula Two.iso / SourceCode / LispExample / LispApp.m < prev    next >
Text File  |  1995-06-12  |  3KB  |  137 lines

  1. /*
  2. **    LispApp.m
  3. **    Appkit-based front-end for a separate lisp process.
  4. **    Lee Boynton, NeXT, Inc., 1989
  5. */
  6.  
  7. #import <string.h>
  8. #import <stdio.h>
  9. #import <defaults/defaults.h>
  10. #import <appkit/Listener.h>
  11. #import <appkit/Window.h>
  12. #import "LispListener.h"
  13. #import "LispApp.h"
  14.  
  15. /*
  16. ** This new Listener responds to the "appEvaluate:" message, which can be
  17. ** sent from any speaker (in another process, for example). See the 
  18. ** 'lispEvaluate' example of sending this message. This appkit 'Listener'
  19. ** subclass should not be confused with the Lisp 'Listener', a completely
  20. ** different animal.
  21. */
  22.  
  23. @interface  LispAppListener : Listener {}
  24. - (int)appEvaluate:(char *)theString;
  25. @end
  26.  
  27. @implementation LispAppListener
  28. static NXRemoteMethod evalMethod;
  29. -(int)appEvaluate:(char *)theString
  30. {
  31.     id _NXd;
  32.     int r;
  33.     if (_NXd = NXResponsibleDelegate(self, @selector(appEvaluate:))) {
  34.     [_NXd appEvaluate:theString];
  35.     return 0;
  36.     } else
  37.     return -1;
  38. }
  39. - (NXRemoteMethod *)remoteMethodFor:(SEL)aSel
  40. {
  41.     evalMethod.key = @selector(appEvaluate:);
  42.     evalMethod.types = "c";
  43.     if (evalMethod.key == aSel)
  44.     return &evalMethod;
  45.     else
  46.     return [super remoteMethodFor:aSel];
  47. }
  48.  
  49. - (int) performRemoteMethod : (NXRemoteMethod *) method
  50.                   paramList : (NXParamValue *) paramList;
  51. {
  52.     if (method == &evalMethod)
  53.     return [self appEvaluate:paramList[0].bval.p];
  54.     else
  55.     return [super performRemoteMethod:method paramList:paramList];
  56. }
  57. @end
  58.  
  59. /*
  60. **
  61. */
  62.  
  63. @implementation LispApp
  64.  
  65. + initialize
  66. {
  67.     const NXDefaultsVector LispDefaults = {
  68.     { "LispImage", "cl" },
  69.     { NULL, NULL }
  70.     };
  71.     NXRegisterDefaults("Lisp", LispDefaults);
  72.     return self;
  73. }
  74.  
  75. + new
  76. {
  77.     self = [super new];
  78.     [self setAppListener:[LispAppListener new]];
  79.     return self;
  80. }
  81.  
  82. - setListener:anObject
  83. {
  84.     listener = anObject;
  85.     return self;
  86. }
  87.  
  88. - free
  89. {
  90.     [listener free];
  91.     return [super free];
  92. }
  93.  
  94. - windowWillClose:sender
  95. {
  96.     extern exit();
  97.     [listener removeFromSuperview];
  98.     [listener free];
  99.     exit(0);
  100. }
  101.  
  102. - (int)appOpenFile:(const char *)path type:(const char *)type
  103. {
  104.     if (type && (!strcmp(type, "lisp") || !strcmp(type, "fasl"))) {
  105.     char buf[1024];
  106.     sprintf(buf,"(load \"%s\")\n",path);
  107.     [listener evaluate:buf];
  108.     return YES;
  109.     } else
  110.     return NO;
  111. }
  112.  
  113. - (BOOL)appAcceptsAnotherFile:sender
  114. {
  115.     return YES;
  116. }
  117.  
  118. - (int)appEvaluate:(char *)theString
  119. {
  120.     [listener evaluate:theString];
  121.     return 0;
  122. }
  123.  
  124. - (int)activateSelf:(BOOL)flag
  125. {
  126.     [[listener window] makeKeyAndOrderFront:self];
  127.     return [super activateSelf:flag];
  128. }
  129.  
  130.  
  131. @end
  132.  
  133.  
  134.  
  135.  
  136.  
  137.